<script setup>
function onDragStart(type, event) {
  const dt = event.dataTransfer
  if (!dt) return
  dt.setData('application/x-type', type)
  dt.effectAllowed = 'copyMove'
}
</script>

<template>
  <aside class="palette">
    <h3 class="title">组件</h3>
    <div class="items">
      <button
        class="item"
        draggable="true"
        @dragstart="onDragStart('container', $event)"
      >
        <svg class="icon" aria-hidden="true" viewBox="0 0 1024 1024">
          <use href="#icon-rongqi"></use>
        </svg>
        <span class="label">容器</span>
      </button>
      <button
        class="item"
        draggable="true"
        @dragstart="onDragStart('text', $event)"
      >
        <svg class="icon" aria-hidden="true" viewBox="0 0 1024 1024">
          <use href="#icon-wenben"></use>
        </svg>
        <span class="label">文字</span>
      </button>
    </div>
  </aside>
</template>

<style scoped>
.palette {
  border-right: 1px solid #e5e7eb;
  padding: 16px;
  background: #f9fafb;
}

.title {
  margin: 0 0 12px;
  font-size: 14px;
  color: #374151;
}

.items {
  display: grid;
  gap: 8px;
}

.item {
  appearance: none;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
  cursor: grab;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.item:active {
  cursor: grabbing;
}

.item .icon {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.item .label {
  line-height: 1;
}
</style>



